/**
 * 1. Fix for IE where the image correctly resizes in width but doesn't collapse its height
      (https://github.com/philipwalton/flexbugs/issues/75#issuecomment-134702421)
 */

// Main <figure> that wraps images.
.euiImage {
  display: inline-block;
  max-width: 100%;
  position: relative;
  min-height: 1px; /* 1 */
  line-height: 0; // Fixes cropping when image is resized by forcing its height to be determined by the image not line-height

  // Required for common usage of nesting within EuiText
  .euiImage__img {
    margin-bottom: 0;
  }

  &.euiImage--hasShadow {
    .euiImage__img {
      @include euiBottomShadowMedium;
    }
  }

  .euiImage__button {
    position: relative;
    cursor: pointer;

    // transition the shadow
    transition: all $euiAnimSpeedFast $euiAnimSlightResistance;

    &:focus {
      outline: 2px solid $euiFocusRingColor;
    }

    &:hover .euiImage__icon {
      visibility: visible;
      fill-opacity: 1;
    }

    &--fullWidth {
      width: 100%;
    }
  }

  &.euiImage--allowFullScreen {
    &:hover .euiImage__caption {
      text-decoration: underline;
    }

    &:not(.euiImage--hasShadow) .euiImage__button:hover,
    &:not(.euiImage--hasShadow) .euiImage__button:focus {
      @include euiBottomShadowMedium;
    }

    &.euiImage--hasShadow .euiImage__button:hover,
    &.euiImage--hasShadow .euiImage__button:focus {
      @include euiBottomShadow;
    }
  }

  // These sizes are mostly suggestions. Don't look too hard for meaning in their values.
  // Size is applied to the image, rather than the figure to work better with floats
  &.euiImage--small .euiImage__img {
    width: convertToRem(120px);
  }

  &.euiImage--medium .euiImage__img {
    width: convertToRem(200px);
  }

  &.euiImage--large .euiImage__img {
    width: convertToRem(360px);
  }

  &.euiImage--xlarge .euiImage__img {
    width: convertToRem(600px);
  }

  &.euiImage--fullWidth {
    width: 100%;
  }

  &.euiImage--original {
    .euiImage__img {
      width: auto;
      max-width: 100%;
    }
  }

  &.euiImage--floatLeft {
    float: left;

    &[class*='euiImage--margin'] {
      margin-left: 0;
      margin-top: 0;
    }
  }

  &.euiImage--floatRight {
    float: right;

    &[class*='euiImage--margin'] {
      margin-right: 0;
      margin-top: 0;
    }
  }

  &.euiImage--marginSmall {
    margin: $euiSizeS;
  }

  &.euiImage--marginMedium {
    margin: $euiSize;
  }

  &.euiImage--marginLarge {
    margin: $euiSizeL;
  }

  &.euiImage--marginXlarge {
    margin: $euiSizeXL;
  }
}

// The image itself is full width within the container.
.euiImage__img {
  width: 100%;
  vertical-align: middle;
}

.euiImage__caption {
  @include euiFontSizeS;
  margin-top: $euiSizeXS;
  text-align: center;
}

.euiImage__icon {
  visibility: hidden;
  fill-opacity: 0;
  position: absolute;
  right: $euiSize;
  top: $euiSize;
  transition: fill-opacity $euiAnimSpeedSlow $euiAnimSlightResistance;
  cursor: pointer;
}

// The FullScreen image that optionally pops up on click.
.euiImage-isFullScreen {
  position: relative;
  max-height: 80vh;
  max-width: 80vw;
  animation: euiImageFullScreen $euiAnimSpeedExtraSlow $euiAnimSlightBounce;

  &:hover {
    .euiImage__button {
      @include euiBottomShadow;
    }

    .euiImage__caption {
      text-decoration: underline;
    }
  }

  &__img {
    max-height: 80vh;
    max-width: 80vw;
    vertical-align: middle;
    cursor: pointer;
    transition: all $euiAnimSpeedFast $euiAnimSlightResistance;
  }
}

.euiImage-isFullScreenCloseIcon {
  position: absolute;
  right: $euiSize;
  top: $euiSize;
  pointer-events: none;
}

@keyframes euiImageFullScreen {
  0% {
    opacity: 0;
    transform: translateY($euiSizeXL * 2);
  }

  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

@include euiBreakpoint('xs', 's', 'm') {
  .euiImage {
    &.euiImage--floatLeft,
    &.euiImage--floatRight {
      float: none;

      // Return back to whatever margin settings were set without the float
      &[class*='euiImage--margin'] {
        margin-top: inherit;
        margin-right: inherit;
        margin-bottom: inherit;
        margin-left: inherit;
      }
    }
  }
}
